package com.hzspace.freemarker.controller;

import com.hzspace.freemarker.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Author: LiuHao
 * @Descirption:
 * @Date: 2020/2/26_20:08
 */
@Controller
public class UserController {

    @GetMapping("/user")
    public String user(Model model) {
        List<User> list = new ArrayList();
        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setId((long) i);
            user.setUsername("hz" + i);
            user.setAddress("www.hzspace.top" + i);
            user.setGender(random.nextInt(3));//0表示男 1表示女 其他代表未知
            list.add(user);
        }
        model.addAttribute("users", list);
        model.addAttribute("hello", "<h1>hello</h1>");
        model.addAttribute("world", "<h1>world</h1>");
        return "user";
    }
}
